/*
 * @lc app=leetcode.cn id=500 lang=cpp
 *
 * [500] 键盘行
 */

// @lc code=start
class Solution
{
public:
  vector<string> findWords(vector<string>& words)
  {
    vector<string> kb = {"qwertyuiop", "asdfghjkl", "zxcvbnm"};
    auto get_row = [&](const char& c) -> int {
      int i = 0;
      while (i < 3 && kb[i].find(c) == string::npos)
        ++i;
      return i;
    };
    vector<string> ans;
    for (const string& str : words) {
      int row = get_row(tolower(str[0]));
      int i = 1;
      for (; i < str.size(); ++i)
        if (kb[row].find(tolower(str[i])) == string::npos)
          break;
      if (i == str.size())
        ans.push_back(str);
    }
    return ans;
  }
};
// @lc code=end
